/* 
 * File:   HNode.h
 * Author: jorge
 *
 * Created on April 23, 2013, 10:01 PM
 */

#ifndef HNODE_H
#define	HNODE_H

template<class T>
class HNode
{
public:

    HNode()
    {
        this->left = 0;
        this->right = 0;
    }

    HNode(T data)
    {
        inicilize(data);
    }

    ~HNode()
    {
        if(!this->left)
        {
            delete this->left;
        }
        if(!this->right)
        {
            delete this->right;
        }
    }

    bool operator==(HNode<T> node)
    {
        return node.getValue() == this->data;
    }

    bool operator>=(HNode<T> node)
    {
        return this->getValue() >= node.getValue();
    }

    HNode& operator=(HNode & other)
    {
        inicilize(other.data);
        
        return *this;
    }

    T& getValue()
    {
        return this->data;
    }

    void setData(T data)
    {
        this->data = data;
    }

    void setLeft(T data)
    {
        if(!this->left)
        {
            this->left = new HNode(data);
        }else
        {
            this->left->setData(data);
        }
    }

    void setRight(T data)
    {
        if(!this->right)
        {
            this->right = new HNode(data);
        }else
        {
            this->right->setData(data);
        }
    }

    T getLeftValue()
    {
        return this->left->getValue();
    }

    T getRightValue()
    {
        return this->right->getValue();
    }

private:
    void inicilize(const T& t)
    {
        this->data = t;
        this->left = 0;
        this->right = 0;
    }

private:
    T data;
    HNode<T>* left;
    HNode<T>* right;
};

#endif	/* HNODE_H */

